import sys
import random
import time

from PIL import Image, ImageDraw

im = Image.open('lsb_2.bmp')  # 需要反变换的图片
width, height = im.size
lsb_data_cnt = 0

cnt = 0
flag = 0

f = open("relsb_bin.txt", "w")
f.close()
f = open("relsb_bin.txt", "a+")  # 获取反二进制文件

for y in range(height):
    for x in range(width):
        pix = im.getpixel((x, y))  # 依次获取原图像素点
        # print(pix[0], pix[1], pix[2])  # 调试信息
        pix_b = pix[2]
        pix_b_bin = bin(pix_b) # 二进制
        # print(pix_b_bin)
        pix_b_bin_last = pix_b_bin[-1:]

        #if cnt % 4 == 0 and flag == 1:
         #   f.write("\n")
        cnt += 1
        flag = 1
        f.write(pix_b_bin_last)
        #print(pix_b_bin_last, end="")

f.close()

f = open("relsb_bin.txt", "r")

bin_list = f.readlines()
# print(type(bin_list))
for i in bin_list:
    i = int(i, 2)
    i = hex(i)
    print(i[2:], end="")